In [1]:
import tensorflow as tf

x = tf.placeholder(tf.string)

with tf.Session() as sess:
    output = sess.run(x, feed_dict={x: 'Hello World with Placeholder'})

print(output)


Hello World with Placeholder

Placeholders have types


In [2]:
y = tf.placeholder(tf.int32)
z = tf.placeholder(tf.float32)

In [4]:
with tf.Session() as sess:
    output = sess.run(y, feed_dict={x: 'Test String', y: 123, z: 45.67})

print(output)


123

and if you pass the wrong type you get an error


In [8]:
with tf.Session() as sess:
    output = sess.run(y, feed_dict={y: 'Hello'})

print(output)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-e2d3ac5f480b> in <module>()
      1 with tf.Session() as sess:
----> 2     output = sess.run(y, feed_dict={y: 'Hello'})
      3 
      4 print(output)

/Users/darienmt/miniconda3/envs/IntroToTensorFlow/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    765     try:
    766       result = self._run(None, fetches, feed_dict, options_ptr,
--> 767                          run_metadata_ptr)
    768       if run_metadata:
    769         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/Users/darienmt/miniconda3/envs/IntroToTensorFlow/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
    936                 ' to a larger type (e.g. int64).')
    937 
--> 938           np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
    939 
    940           if not subfeed_t.get_shape().is_compatible_with(np_val.shape):

/Users/darienmt/miniconda3/envs/IntroToTensorFlow/lib/python3.6/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
    480 
    481     """
--> 482     return array(a, dtype, copy=False, order=order)
    483 
    484 def asanyarray(a, dtype=None, order=None):

ValueError: invalid literal for int() with base 10: 'Hello'

In [ ]: